package com.xkstream.client.presenter.kt

import android.os.Parcel
import android.os.Parcelable
import com.xkstream.client.api.kt.MyZoneApi
import com.xkstream.client.api.kt.MyZoneService
import com.xkstream.client.base.BaseData
import com.xkstream.client.base.BasePresenterImpl
import com.xkstream.client.rx.RxHelper
import com.xkstream.client.rx.RxObserver

class SendTalkPresenter() : BasePresenterImpl(), SendTalkContract.Presenter {

    var myzoneService: MyZoneService? = null
    var view: SendTalkContract.View? = null


    constructor(view: SendTalkContract.View) : this() {
        this.view = view
        this.myzoneService = MyZoneApi.getInstance().service
    }

    override fun publishBlog(params: Map<String, String>) {
        view?.showLoading()
        myzoneService?.publishBlog(params)
                ?.compose(RxHelper.toUI())
                ?.subscribe(object : RxObserver<BaseData<Any?>>(this) {
                    override fun onFail(message: String) {
                        view?.showError(message)
                        view?.hideLoading()
                    }

                    override fun onSuccess(t: BaseData<Any?>?) {
                        view?.hideLoading()
                        view?.showResult(t)
                    }
                })

    }
}